﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DHQGHN.DAL.Common;
using DHQGHN.DAL.DAO.Admin;
using DHQGHN.DAL.Models.Admin;

namespace DHQGHN.DAL.BO.Admin
{
    public class DeathCauseBO : BaseBO
    {
        #region Field list from database
        public const string FIELD_ID = "DEATH_CAUSE_ID";
        public const string FIELD_NAME = "NAME";
        public const string FIELD_CODE = "CODE";
        public const string FIELD_DESCRIPTIONS = "DESCRIPTIONS";
        public const string FIELD_DELETED = "DELETED";
        #endregion
        public const string FIELD_RECORD_COUNT = "RecordCount";

        private String _connectionString;

        public DeathCauseBO(string connString)
        {
            this._connectionString = connString;

        }
        public DeathCauseBO()
        {
            this._connectionString = Common.ConnectionUtil.TKTHDS_METADATA_CONNECTION_STRING;

        }

        public DeathCauseDAO _DeathCauseDAO;

        public DeathCauseDAO CreateSQLDAO()
        {
            return new DeathCauseDAO(_connectionString, DEFAULT_MAPPER_TYPE);
        }

        public DataPage<DeathCauseModel> GetDynamicListPaging(DeathCauseModel aModel, int pageSize, int pageIndex, bool compareEqual)
        {
            try
            {
                _DeathCauseDAO = CreateSQLDAO();
                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {DeathCauseModel.FIELD_ID,FIELD_ID},
                    {DeathCauseModel.FIELD_NAME,FIELD_NAME},
                    {DeathCauseModel.FIELD_CODE,FIELD_CODE},  
                    {DeathCauseModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},
                    {DeathCauseModel.FIELD_DELETED,FIELD_DELETED},
                    {DeathCauseModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };
                return _DeathCauseDAO.GetDynamicListPaging(aModel, pageSize, pageIndex, mapDictionary, compareEqual);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public DeathCauseModel GetDeathCauseById(string id)
        {
            try
            {
                _DeathCauseDAO = CreateSQLDAO();

                Dictionary<String, String> mapDictionary = new Dictionary<string, string>()
                {
                    {DeathCauseModel.FIELD_ID,FIELD_ID},
                    {DeathCauseModel.FIELD_NAME,FIELD_NAME},
                    {DeathCauseModel.FIELD_CODE,FIELD_CODE},  
                    {DeathCauseModel.FIELD_DESCRIPTIONS,FIELD_DESCRIPTIONS},  
                    {DeathCauseModel.FIELD_DELETED,FIELD_DELETED},
                    {DeathCauseModel.FIELD_RECORD_COUNT, FIELD_RECORD_COUNT}
                };

                return _DeathCauseDAO.GetById(id, mapDictionary);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool createOrUpdateDeathCause(DeathCauseModel model)
        {
            try
            {
                _DeathCauseDAO = CreateSQLDAO();
                return _DeathCauseDAO.createOrUpdateDeathCause(model);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool deleteDeathCause(string[] listID)
        {
            try
            {
                _DeathCauseDAO = CreateSQLDAO();
                return _DeathCauseDAO.deleteDeathCause(listID);
            }
            catch (Exception e)
            {
                return false;
            }
        }

        public bool activeDeathCause(string id, int request)
        {
            try
            {
                _DeathCauseDAO = CreateSQLDAO();
                return _DeathCauseDAO.activeDeathCause(id, request);
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}